﻿/**
 * @file transport.h
 * @date 2021/07/08 19:25
 * @author joehuang huangge.cool@163.com
 * @brief 中台封装的Transport
 * @details 
 * @version v1.0.0
 * @copyright Copyright © 2021 All Rights Reserved 上海欢乐互娱网络科技有限公司
*/
#pragma once

#include "rpc_transport.h"
#include "knet/knet.h"

namespace link_util {
class PlatformTrans : public rpc::Transport {
    kchannel_ref_t* channel_ { nullptr };
public:
    PlatformTrans(kchannel_ref_t* channel);
    virtual ~PlatformTrans();
    // Send data
    // @param data The data need to send
    // @param size data size in byte
    // @return How many bytes sent, <= 0 means error
    virtual int send(const char* data, int size) override;
    // Copy data from stream but doesn't remove it
    // @param data The data need to copy
    // @param size data size in byte
    // @return How many bytes need to copy, <= 0 means error
    virtual int peek(char* data, int size) override;
    // Receive data
    // Copy data from stream and remove them
    // @param data The data need to move
    // @param size The data size in byte
    // @return How many bytes need to move, <= 0 means error
    virtual int recv(char* data, int size) override;
    // Ignore some bytes in stream
    // @param size The data size in byte need to ignore
    virtual int skip(int size) override;
    // Returns how many bytes in stream
    virtual int size() override;
    // Check whether stream has been closed
    virtual bool isClose() override;
    // Close stream
    virtual void close() override;
};
}
